package cn.lili.eventbus.handlers;

import cn.lili.consumer.event.StoreSettingChangeEvent;
import cn.lili.eventbus.event.StoreEvent;
import cn.lili.modules.store.entity.dos.Store;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Sylow
 * @Description
 * @Date: Created in 15:03 2025/6/19
 */
@Slf4j
@Service
public class StoreEventHandler {

    @Autowired
    private List<StoreSettingChangeEvent> storeSettingChangeEventList;

    @EventListener
    public void handleStoreEvent(StoreEvent event) {

        switch (event.getStoreTagsEnum()){
            //修改店铺
            case EDIT_STORE_SETTING:
                for (StoreSettingChangeEvent storeSettingChangeEvent : storeSettingChangeEventList) {
                    try {
                        Store store = (Store)event.getData();
                        storeSettingChangeEvent.storeSettingChange(store);
                    } catch (Exception e) {
                        log.error("店铺{},在{}业务中，状态修改事件执行异常",
                                ((Store)event.getData()).getStoreName(),
                                storeSettingChangeEvent.getClass().getName(),
                                e);
                    }
                }
                break;
            default:
                break;
        }
    }
}
